package com.ruoyi.jiuzai.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.jiuzai.domain.Wuzihuisou;
import com.ruoyi.jiuzai.service.IWuzihuisouService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 物资回收Controller
 * 
 * @author ruoyi
 * @date 2025-06-25
 */
@RestController
@RequestMapping("/jiuzai/wuzihuisou")
public class WuzihuisouController extends BaseController
{
    @Autowired
    private IWuzihuisouService wuzihuisouService;

    /**
     * 查询物资回收列表
     */
    @PreAuthorize("@ss.hasPermi('jiuzai:wuzihuisou:list')")
    @GetMapping("/list")
    public TableDataInfo list(Wuzihuisou wuzihuisou)
    {
        startPage();
        List<Wuzihuisou> list = wuzihuisouService.selectWuzihuisouList(wuzihuisou);
        System.out.println("回收的详细数据"+list);
        return getDataTable(list);
    }

    /**
     * 导出物资回收列表
     */
    @PreAuthorize("@ss.hasPermi('jiuzai:wuzihuisou:export')")
    @Log(title = "物资回收", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Wuzihuisou wuzihuisou)
    {
        List<Wuzihuisou> list = wuzihuisouService.selectWuzihuisouList(wuzihuisou);
        ExcelUtil<Wuzihuisou> util = new ExcelUtil<Wuzihuisou>(Wuzihuisou.class);
        util.exportExcel(response, list, "物资回收数据");
    }

    /**
     * 获取物资回收详细信息
     */
    @PreAuthorize("@ss.hasPermi('jiuzai:wuzihuisou:query')")
    @GetMapping(value = "/{hId}")
    public AjaxResult getInfo(@PathVariable("hId") Long hId)
    {
        System.out.println("回收的详细数据"+wuzihuisouService.selectWuzihuisouByHId(hId));
        return success(wuzihuisouService.selectWuzihuisouByHId(hId));
    }

    /**
     * 新增物资回收
     */
    @PreAuthorize("@ss.hasPermi('jiuzai:wuzihuisou:add')")
    @Log(title = "物资回收", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Wuzihuisou wuzihuisou)
    {
//        return toAjax(wuzihuisouService.insertWuzihuisou(wuzihuisou));
        int rows = wuzihuisouService.insertWuzihuisou(wuzihuisou);
        if (rows > 0) {
            // 返回包含生成ID的完整实体
            return success(wuzihuisou);
        }
        return error("新增失败");
    }

    /**
     * 修改物资回收
     */
    @PreAuthorize("@ss.hasPermi('jiuzai:wuzihuisou:edit')")
    @Log(title = "物资回收", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Wuzihuisou wuzihuisou)
    {
        return toAjax(wuzihuisouService.updateWuzihuisou(wuzihuisou));
    }

    /**
     * 删除物资回收
     */
    @PreAuthorize("@ss.hasPermi('jiuzai:wuzihuisou:remove')")
    @Log(title = "物资回收", businessType = BusinessType.DELETE)
	@DeleteMapping("/{hIds}")
    public AjaxResult remove(@PathVariable Long[] hIds)
    {
        return toAjax(wuzihuisouService.deleteWuzihuisouByHIds(hIds));
    }
}
